home *** CD-ROM | disk | FTP | other *** search
/ Floppyshop 2 / Floppyshop - 2.zip / Floppyshop - 2.iso / diskmags / 3565-4.665 / dmg-3609 / news.txt / project4.asc < prev    next >
Text File  |  1989-04-05  |  17KB  |  404 lines

  1.  
  2.                         ##########################
  3.                         #                        #
  4.                         #    DIGITAL JUNCTION    #
  5.                         #    ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯    #
  6.                         #     INTERFACING 4      #
  7.                         #     ¯¯¯¯¯¯¯¯¯¯¯¯¯      #
  8.                         #                        #
  9.                         #     by Dave Price      #
  10.                         #                        #
  11.                         ##########################
  12.  
  13.  
  14.      Over the past few instalment of Interfacing I have discussed  various 
  15. possibilities  that would enable the transfer of data between the  ST  and 
  16. outside world.
  17.  
  18.        We are now going to put this knowledge to use by carrying out  some 
  19. practical interfacing experiments.  Whilst I shall be basing the  software 
  20. and  hardware around the use of the cartridge and printer ports  there  is 
  21. no  reason  why the experiments cannot be carried out on  other  types  of 
  22. interface  units  such  as  the Maplin RS232 to  8-bit  I/O  port  as  the 
  23. principles  are the same although the software may well need  altering  to 
  24. suit.
  25.  
  26.      Before  starting  I  must draw your attention to  an  amendment  that 
  27. needs  to be made to the suggested printer port module (see  STEN  12).  I 
  28. had missed out a component in my circuit diagram.  The diagram should have 
  29. shown  a  transistor  on  the  strobe  line.  It  is  important  that  the 
  30. transistor  is installed as it provides buffering to the strobe  line  and 
  31. protects   the   sound   chip   from   possible   damage.    See   picture 
  32. file..USEPORT2.PC3 (<SCREENS> folder).
  33.  
  34.      The  first  project  will  prove to be a useful  little  tool  as  it 
  35. provides a visual display of what is going on at the output port and  thus 
  36. can  be very helpful for checking that the port or software is doing  what 
  37. is intended.
  38.  
  39.      PROJECT No.1 - Output Display Unit
  40.      ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
  41.      Basic parts list
  42.  
  43.      1 piece of stripboard 10 strips wide x 15 holes long
  44.      8 Red LED (rectangular makes neat job but 3mm dia. will do
  45.      1 180R 9-pin SIL resistor array (9 pins- 8 resistors 1 common)
  46.      1 ULN2803A Octal Darlington Driver TTL **SEE NOTE BELOW
  47.      1 18-pin DIL socket
  48.      length of 10-way ribbon cable or other flexible insulated wire
  49.  
  50. NOTE:  Above  parts  are for an 8-bit wide port.  If  you  require  16-bit 
  51. double up on components and double width of stripboard.
  52.  
  53.        ULN2803A not absolutly necessary if using buffered output.
  54.        ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
  55.      See picture file..PROJECT1.PC3..(<SCREENS> folder) for layout.
  56.  
  57.      Having  built  the circuit check for  component  orientation,  solder 
  58. bridges and cuts in stripboard have been made in the correct  places.  Now 
  59. connect  the project to your interface unit making sure  connecting  wires 
  60. are in the correct order or if using plugs that they are wired correctly.
  61. NOTE:  If you are connecting the project directly to the printer port  you 
  62. will need a 25-way 'D' type plug.  In either case do not forget to connect 
  63. your 5 volt D.C. supply.
  64.  
  65. **WARNING**  -  Any  peripherals including interfacing  projects  must  be 
  66. connected before powering up your ST.
  67.  
  68.      Upon  switching on your ST you may notice that the LEDs flash on  and 
  69. off once.  This is OK it is only the system setting its self. There may be 
  70. occasion  when  one or two LEDS may stay on,  again,  don't  worry  it  is 
  71. possible  that a spurious pulse may have caused a line to latch  on.  This 
  72. can  be cleared by sending a zero to the port as follows:-Listings in  GFA 
  73. BASIC V3.6
  74.  
  75.  
  76. RESETTING PRINTER PORT - Using hardware as discussed in Interface 3
  77. ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
  78. ~XBIOS(30,$20)   !Switch userport to write mode (See note below)
  79. ~XBIOS(28,0,$81) !Send zero to port
  80.  
  81. NOTE:  ~XBIOS(30,$20)  not  needed  if project is  directly  connected  to 
  82. printer  port.  See  Interface  3  (STEN  12)  for  explanation  of  XBIOS 
  83. routines.
  84.  
  85. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  86.  
  87. RESETTING CARTRIDGE PORT - Using hardware as discussed in Interface 3
  88. ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
  89. DEFFN portout(d%) = PEEK(&HFA0000+d%) !ROM4 select + output data in d%
  90. ~@portout(0)                          !Send zero to port
  91.  
  92. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  93.  
  94.      All  LEDs should now be off indicating that all output lines  are  at 
  95. logic low (0 Volts).
  96.  
  97. This  next  program is just a little test to check each data line  (D0  to 
  98. D7) is operating correctly.
  99.  
  100. (a) Printer Port
  101.  
  102. CLS
  103. ~XBIOS(30,$20)  !Set userport hardware to output mode
  104. DO
  105. LOCATE 10,5
  106. PRINT" THIS ALLOWS YOU TO SET ONE OF THE OUTPUT"
  107. PRINT TAB(9);"LINES(D0 - D7) ON THE PRINTER PORT"
  108. PRINT TAB(9);"ENTER -1 TO SWITCH OFF ALL LINES"
  109. PRINT TAB(9);"PRESS RETURN TO EXIT"
  110. LOCATE 10,12
  111. INPUT"ENTER OUTPUT LINE (0 -7) TO SET ";a$
  112. EXIT IF a$=""
  113. n|=VAL(a$)
  114. x|=2^n|
  115. ~XBIOS(28,x|,$8F)  !Output data in x|
  116. Loop
  117. ~XBIOS(28,0,$8F)   !Reset output (all LEDs off)
  118. END
  119.  
  120. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  121. (b) Cartridge port
  122.  
  123. DEFFN portout(d%)=PEEK(&HFA0000+d%)
  124. CLS
  125. DO
  126. LOCATE 10,5
  127. PRINT" THIS ALLOWS YOU TO SET ONE OF THE OUTPUT"
  128. PRINT TAB(9);"LINES(D0 - D15) ON THE CARTRIDGE PORT"
  129. PRINT TAB(9);"ENTER -1 TO SWITCH OFF ALL LINES"
  130. PRINT TAB(9);"PRESS RETURN TO EXIT"
  131. LOCATE 10,12
  132. INPUT"ENTER OUTPUT LINE (0 - 15) TO SET ";a$
  133. EXIT IF a$=""
  134. n%=VAL(a$)
  135. x%=2^n%
  136. ~@portout(x%)  !Output data in x%
  137. LOOP
  138. ~@portout(0)   !Reset output (all LEDs off)
  139. END
  140.  
  141. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  142.  
  143.      If  you  have wired the LED module correctly,  the number  you  enter 
  144. into the program should turn the corresponding LED on indicating that  the 
  145. line has been set to logic high (+5 volts) i.e.  entering 3 will set  data 
  146. line  D3  and therefore the corresponding LED will be  on.  You  may  have 
  147. noticed  the terms SET and RESET being used when discussing digital  logic 
  148. levels.  Generally, a digital line is SET when at logic high (1) and RESET 
  149. when at logic low (0).
  150.  
  151.  
  152.      Now try the the following program:-
  153. Printer Port
  154.  
  155. CLS
  156. ~XBIOS(30,$20)
  157. FOR x|=0 TO 255
  158. PRINT x|; HEX$(x|)
  159. ~XBIOS(28,x|,$8F)
  160. DELAY 5
  161. NEXT x|
  162. PRINT"Press any key to exit"
  163. ~INP(2)
  164. ~XBIOS(28,0,$8F)
  165. END
  166.  
  167. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  168.  
  169. Cartridge Port
  170.  
  171. DEFFN portout(d%)=PEEK(&HFA0000+d%)
  172. CLS
  173. FOR x%=0 TO 65535
  174. PRINT x%; HEX$(x%)
  175. ~@portout(x%)
  176. DELAY 5      ! wait for 5 seconds
  177. NEXT x%
  178. PRINT"Press any key to exit"
  179. ~INP(2)
  180. ~@portout(0)
  181. END
  182.  
  183. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  184.  
  185.      Running  this program will cause a list of decimal numbers from 0  to 
  186. 255   (65535  if  using  16-bit  on  cartridge  port)  along  with   their 
  187. hexidecimal  equivalents  00  to FF (FFFF if 16-bit) to  be  displayed  on 
  188. screen.  At the same time the LEDs will display the binary equivalents  as 
  189. the  numbers  increase.  The  program has a 5 second  delay  between  each 
  190. number  which  should be ample time to note the number  displayed  on  the 
  191. screen  and the LED pattern.  To change the delay time just alter  program 
  192. line DELAY 5.
  193.  
  194.      The following program is a little more exciting.  It "walks" a  light 
  195. along the row of LEDs in the same fashion used by many advertising signs.
  196.  
  197. NOTE:  To save repetition I shall, from now on, only be providing listings 
  198. for  use  with  the suggested printer port  interface.  Anyone  using  the 
  199. cartridge  port should not have any difficulty in converting the  programs 
  200. to  suit.  The  previous  programs should serve as a  guide.  If  any  new 
  201. routines  not  mentioned  before do arise then I  shall  indicate  in  the 
  202. printer  port listings where any alterations may need to be  carried  out. 
  203. However, If anyone has problems then let me know.
  204.  
  205. Running light program
  206.  
  207. PRINT "Press mouse button to exit"
  208. REPEAT
  209. x=1
  210. REPEAT
  211. ~XBIOS(28,x|,$8F)
  212. PAUSE 5  x=x*2
  213. UNTIL x=256
  214. UNTIL MOUSEK
  215. END
  216.  
  217. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  218.  
  219.      These  small programs should give a reasonable indication as  to  how 
  220. easy  it  is to send data and control signals from the ST.  We  shall  now 
  221. move onto simple inputting of data but before we do another small  circuit 
  222. needs to be built.
  223.  
  224. Components list for Input switch module
  225.  
  226. 1 stripboard 10 strips x 15 holes
  227. 1 octal DIL switch
  228. 1 16-pin DIL socket
  229. 1 100k 9-pin SIL resistor network
  230. wire and connectors for data and power lines.
  231.  
  232. See picture file..PROJECT2.PC3..(<SCREENS folder) for layout.
  233.  
  234. Double up on the quantity for 16-bit inputs.
  235.  
  236.      Connect  the  new  circuit  to your interface  unit  or  directly  to 
  237. printer  port and set DIL switches in the OFF position.  Now type  in  and 
  238. run the following GFA BASIC V3.6 program:-
  239.  
  240. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  241.  
  242. ~XBIOS(29,$DF)     !Resets  strobe line low to  switch  suggested  printer 
  243. port                   !interface to input mode.
  244. r|=XBIOS(28,0,$0F)!switches  printer port data lines to input  and  places                   
  245. !data in r|
  246. PRINT "Data on input port reads";r|
  247. PRINT "Press any key to exit"
  248. ~INP(2)
  249. ~XBIOS(28,0,$8F)  !  Reset  printer port to output as  per  normal  system                   
  250. ! setting
  251. END
  252.  
  253. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  254.  
  255. Cartridge  port  users  should use  r%=DPEEK(&HFB0000)  instead  of  XBIOS 
  256. routine
  257.  
  258. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  259.  
  260.      The  program should display a zero indicating all input lines are  at 
  261. logic  0.  If  you now switch any amount of the switches on  and  run  the 
  262. program  again  the screen will display the decimal number  equivalent  of 
  263. the  switch settings.  The switches that are in the on position  sets  the 
  264. relevant input line (logic 1).  For example,  if the switches on D7,  D3 & 
  265. D0  input  lines are on and the rest are off the  binary  number  10001001 
  266. will be present at the input port.  Running the above program will display 
  267. 137, the decimal equivalent.  
  268.      It  would be very useful to be able to combine the input  and  output 
  269. of data i.e.  monitor the input signals,  process them and then output  as 
  270. required.  This cannot be done by direct connection to the printer port as 
  271. the 8-bit data lines can only be set for input or output,  they cannot  be 
  272. mixed.  I  therefore suggest that the circuit outlined or similar  in  the 
  273. last  installment is used.  Cartridge port users are ok as separate  input 
  274. and  output  lines  are available.  See  previous  digital  junctions  for 
  275. further information.
  276.  
  277.      Carrying  out input and output of data together is  straight  foward. 
  278. Connect  the LED module into your output port,  the switch module  to  the 
  279. input  port and run the program listed below.  The program  simpley  reads 
  280. the input port,  prints the decimal and hex value on screen then  displays 
  281. the binary value on the LED module.
  282.  
  283. INPUT/OUTPUT Program.
  284.  
  285. ~XBIOS(29,$DF)    !strobe low - interface port to input mode
  286. r=XBIOS(28,0,$0F) !data in and store in r
  287. PRINT "DATA ON INPUT READS ";r,HEX$(r)
  288. ~XBIOS(30,$20)      !strobe   high  -  interface  port  to   output   mode 
  289. ~XBIOS(28,r,$8F)  !output data
  290. END
  291.  
  292. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  293.  
  294.      This  program  can be placed in a loop to save having  to  constantly 
  295. run it every time you change the switch pattern, I leave that to you.
  296.  
  297.      The above example is really no more than a glorified switch but  does 
  298. demonstrate  the basic principles.  The last example for this  installment 
  299. is  a little more sophisticated.  It demonstrates the principles of how  a 
  300. computer  can  be  used to continuously monitor its input  port  and  only 
  301. react  when a certain code is received,  rather like an  electronic  coded 
  302. lock.
  303.  
  304. Lock program
  305.  
  306. code=143           ! or any number between 0 and 255
  307. REPEAT
  308. ~XBIOS(30,$20)     ! strobe high
  309. ~XBIOS(28,255,$8F) ! set all LEDs on
  310. DELAY 0.5          ! delay for half second
  311. ~XBIOS(28,0,$8F)   ! all LEDs off
  312. ~XBIOS(29,$DF)     ! strobe low
  313. ~XBIOS(28,0,$0F)   ! read input
  314. UNTIL r=code
  315. ~XBIOS(30,$20)     ! strobe high
  316. ~XBIOS(28,255,$8F) ! set all LEDs on
  317. SOUND 1,15,1,4,20
  318. SOUND 2,15,4,4,20  ! make a noise
  319. SOUND 3,15,8,4,20
  320. WAVE 7,7,0,65535,300
  321. PRINT "YOU MAY NOW ENTER"
  322. PRINT
  323. PRINT "PRESS ANY KEY TO EXIT PROGRAM"
  324. ~INP(2)
  325. ~XBIOS(28,0,$8F)   ! all LEDs off
  326. END
  327.  
  328. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  329.  
  330.      This  program flashes the LEDs and monitors the input port.  As  soon 
  331. as  the  input data,  set by the switches,  matches the number  stored  in 
  332. variable 'code' (143 decimal or 10001111 binary  i.e.  switches for  lines 
  333. D7,D3,D2,D1,D0  set  on all others off in our example) the  program  exits 
  334. the REPEAT - UNTIL loop,  sets all the LEDs on, makes a noise and displays 
  335. a message.
  336.  
  337.      Well thats it for this issue.  I hope you have found the examples and 
  338. circuits easy to follow,  I have tried to keep things simple.  If you have 
  339. any  problems  then please get in touch.  The program listings  have  been 
  340. kept to the bare minimum in order that you can see whats going on,  if you 
  341. want  to write your own with GEM buttons etc then do so there  is  nothing 
  342. stopping  you.  Also don't be afraid to experiment,  how about  writing  a 
  343. program  to  simulate traffic lights at a junction using the  switches  to 
  344. simulate the induction loop vehicle sensors buried in the road.
  345.  
  346. Next Issue
  347. ----------     I  hope to discuss the methods required to  enable  control 
  348. of  filement  lamps  (as opposed to LEDs) and  electric  motors  including 
  349. stepper motors.
  350.  
  351. Notice Board
  352. ------------    Unless otherwise stated, all  modifications,  experiments, 
  353. hardware  and  software  discussed in this column are tested on  a  1  Meg 
  354. Atari  STFM  with  high resolution  monitor.  However,  the  projects  and 
  355. software should work on most other set ups as I have tried to keep  things 
  356. to standard.
  357.  
  358.      If  you  should spot an error or know of a better  way  of  achieving 
  359. something  be  it  with hardware or software then please let  me  know  so  
  360. that  I  may  pass the knowledge on through this  column.  What  may  seem 
  361. obvious  to you may have been over looked by others and could be just  the 
  362. answer they are looking for. 
  363.  
  364.  
  365.      STEN  is  here because enthusiasts are willing to pass on  what  they 
  366. know.
  367.  
  368. Important bit
  369. -------------     Whilst every effort has been made to make sure that  the 
  370. information  given  in this article is correct neither I or  STEN  can  be 
  371. held  responsible for any damage which may arise due to  readers  carrying 
  372. out  modifications  or connecting any devices directly  or  indirectly  to 
  373. their computers.
  374.  
  375.                                              "By order of der Management"
  376.  
  377. +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  378. + Bibliography - Suggestions for further reading                        +                        
  379. +                                                                       +
  380. + ------------                                                          + 
  381. +                                                                       +
  382. + Concise Atari ST 68000 Referance Guide by K.D.Peel                    +                   
  383. +                                                                       +
  384. + Atari ST Internals by Bruckmann, English & Gerits                     +                     
  385. +                                                                       +
  386. + GFA BASIC V3.6 Manual                                                 + 
  387. +                                                                       +
  388. + Microprocessor Interfacing by R.E.Vears                               + 
  389. +                                                                       +
  390. + Interfacing your BBC Microcomputer by R.Morgan, W.McClean & J.Rosell  + 
  391. +                                                                       +
  392. + Practical Digital Electronics Handbook by Mike Tooley                 + 
  393. +                                                                       +
  394. + Introducing Atari ST Machine code by Roger Pearson & Sean Hodgson     + 
  395. +                                                                       +
  396. +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  397.  
  398. **************************************************************************
  399. *                                                                        *
  400. * Dave Price, 42 Foxglove Green, Willesborough, Ashford, Kent. TN24 0RJ  * 
  401. *                                                                        *
  402. **************************************************************************
  403.  
  404.